package ${packageRootName}.controller;

import ${packageRootName}.entity.${modelBig};
import ${packageRootName}.pojo.vo.PageBean;
import ${packageRootName}.pojo.vo.Result;
import ${packageRootName}.pojo.vo.ResultBuilder;
import ${packageRootName}.service.I${modelBig}Service;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
public class ${controllerClassName}Controller {
    @Autowired
    private I${modelBig}Service ${modelSmall}Service;


    @ApiOperation(value = "")
    @PostMapping("${restful}/edit")
    public Result<${modelBig}> edit(@RequestBody ${modelBig} dto) {
        if (dto.getId() == null){
            //新增
            ${modelSmall}Service.insert(dto);
        }else {
            //修改
            ${modelSmall}Service.update(dto);
        }
        return ResultBuilder.getSuccess(dto);
    }


    @ApiOperation(value = "")
    @PostMapping("${restful}/delete")
    public Result delete(@RequestBody ${modelBig} dto) {
        ${modelSmall}Service.delete(dto.getId());
        return ResultBuilder.getSuccess();
    }


    @ApiOperation(value = "")
    @GetMapping("${restful}/page")
    public Result<PageBean<${modelBig}>> page(
        @RequestParam(value="pageNum",required = false,defaultValue = "1")Integer pageNum,
        @RequestParam(value="pageSize",required = false,defaultValue = "10")Integer pageSize) {
        PageBean<${modelBig}> page = ${modelSmall}Service.page(pageNum, pageSize);
        return ResultBuilder.getSuccess(page);
    }


    @ApiOperation(value = "")
    @GetMapping("${restful}/info")
    public Result<${modelBig}> info(Integer ${modelSmall}Id) {
        if (${modelSmall}Id == null){
            return ResultBuilder.getError("参数错误");
        }
        ${modelBig} ${modelSmall} = ${modelSmall}Service.getById(${modelSmall}Id);
        return ResultBuilder.getSuccess(${modelSmall});
    }
}
